﻿using System;
using System.Runtime.InteropServices;

using HRESULT = System.Int32;

namespace Microsoft.Office.OneNote.Interop
{
    [ComImport]
    [CoClass(typeof(OneNoteApplicationClass))]
    [Guid("2DA16203-3F58-404f-839D-E4CDE7DD0DED")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable)]
    internal interface IOneNoteApplication
    {
        // Hierarchy Level Operations

        [PreserveSig]
        [DispId(0x60020000)]
        HRESULT GetHierarchy(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrStartNodeID,
            [In]                                     HierarchyScope hsScope,
            [Out, MarshalAs(UnmanagedType.BStr)] out String bstrHierarchyXmlOut);

        [PreserveSig]
        [DispId(0x60020001)]
        HRESULT UpdateHierarchy(
            [In, MarshalAs(UnmanagedType.BStr)] String bstrChangesXmlIn);

        [PreserveSig]
        [DispId(0x60020002)]
        HRESULT OpenHierarchy(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrPath,
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrRelativeToObjectID,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrObjectID,
            [In]                                     CreateHierarchyType cftIfNotExist);

        [PreserveSig]
        [DispId(0x60020003)]
        HRESULT DeleteHierarchy(
            [In, MarshalAs(UnmanagedType.BStr)] String bstrObjectID,
            [In, Optional]                      DateTime dateExpectedLastModified);

        [PreserveSig]
        [DispId(0x60020004)]
        HRESULT CreateNewPage(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrSectionID,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrPageID,
            [In]                                     NewPageStyle npsNewPageStyle);

        [PreserveSig]
        [DispId(0x60020005)]
        HRESULT CloseNotebook(
            [In, MarshalAs(UnmanagedType.BStr)] String bstrNotebookID);

        [PreserveSig]
        [DispId(0x60020006)]
        HRESULT GetHierarchyParent(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrObjectID,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrParentID);

        // Page content level operations
        [PreserveSig]
        [DispId(0x60020007)]
        HRESULT GetPageContent(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrPageID,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrPageXmlOut,
            [In]                                     PageInfo pageInfoToExport);

        [PreserveSig]
        [DispId(0x60020008)]
        HRESULT UpdatePageContent(
            [In, MarshalAs(UnmanagedType.BStr)] String bstrPageChangesXmlIn,
            [In]                                DateTime dateExpectedLastModified);

        [PreserveSig]
        [DispId(0x60020009)]
        HRESULT GetBinaryPageContent(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrPageID,
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrCallbackID,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrBinaryObjectB64Out);

        [PreserveSig]
        [DispId(0x6002000a)]
        HRESULT DeletePageContent(
            [In, MarshalAs(UnmanagedType.BStr)] String bstrPageID,
            [In, MarshalAs(UnmanagedType.BStr)] String bstrObjectID,
            [In]                                DateTime dateExpectedLastModified);

        // Navigation
        [PreserveSig]
        [DispId(0x6002000b)]
        HRESULT NavigateTo(
            [In, MarshalAs(UnmanagedType.BStr)]        String bstrHierarchyObjectID,
            [In, MarshalAs(UnmanagedType.BStr)]        String bstrObjectID,
            [In, MarshalAs(UnmanagedType.VariantBool)] Boolean fNewWindow);

        // Publish
        [PreserveSig]
        [DispId(0x6002000c)]
        HRESULT Publish(
            [In, MarshalAs(UnmanagedType.BStr)] String bstrHierarchyID,
            [In, MarshalAs(UnmanagedType.BStr)] String bstrTargetFilePath,
            [In]                                PublishFormat pfPublishFormat,
            [In, MarshalAs(UnmanagedType.BStr)] String bstrCLSIDofExporter);

        [PreserveSig]
        [DispId(0x6002000d)]
        HRESULT OpenPackage(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrPathPackage,
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrPathDest,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrPathOut);

        // Hyperlinks
        [PreserveSig]
        [DispId(0x6002000e)]
        HRESULT GetHyperlinkToObject(
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrHierarchyID,
            [In, MarshalAs(UnmanagedType.BStr)]      String bstrPageContentObjectID,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrHyperlinkOut);

        // Search
        [PreserveSig]
        [DispId(0x6002000f)]
        HRESULT FindPages(
            [In, MarshalAs(UnmanagedType.BStr)]        String bstrStartNodeID,
            [In, MarshalAs(UnmanagedType.BStr)]        String bstrSearchString,
            [Out, MarshalAs(UnmanagedType.BStr)]   out String pbstrHierarchyXmlOut,
            [In, MarshalAs(UnmanagedType.VariantBool)] Boolean fIncludeUnindexedPages,
            [In, MarshalAs(UnmanagedType.VariantBool)] Boolean fDisplay);

        [PreserveSig]
        [DispId(0x60020010)]
        HRESULT FindMeta(
            [In, MarshalAs(UnmanagedType.BStr)]        String bstrStartNodeID,
            [In, MarshalAs(UnmanagedType.BStr)]        String bstrSearchStringName,
            [Out, MarshalAs(UnmanagedType.BStr)]   out String pbstrHierarchyXmlOut,
            [In, MarshalAs(UnmanagedType.VariantBool)] Boolean fIncludeUnindexedPages);

        [PreserveSig]
        [DispId(0x60020011)]
        HRESULT GetSpecialLocation(
            [In]                                     SpecialLocation slToGet,
            [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrSpecialLocationPath);
    }

    [ComImport]
    [Guid("C9590FA7-2132-47FB-9A78-AF0BF19AF4E6")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable)]
    internal interface IOneNoteAddIn
    {
        [DispId(0x60020000)]
        [return: MarshalAs(UnmanagedType.VariantBool)]
        Boolean OnClick([In, MarshalAs(UnmanagedType.BStr)] String bstrActivePageID);
        
        [DispId(0x60020001)]
        [return: MarshalAs(UnmanagedType.VariantBool)]
        Boolean OnEvent(
            [In]                                OneNoteAddInEvent evt, 
            [In, MarshalAs(UnmanagedType.BStr)] String            bstrParameter);
    }

    [ComImport]
    [ClassInterface(ClassInterfaceType.None)]
    [TypeLibType(TypeLibTypeFlags.FCanCreate)]
    [Guid("0039FFEC-A022-4232-8274-6B34787BFC27")]
    internal class OneNoteApplicationClass
    {
    }
}